﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo.PeInspector.ObjectGraphs
{
	class DelegatedTemplate<TNode> : NodeTemplate<TNode>
	{
		public Predicate<TNode> Predicate { get; private set; }

		public DelegatedTemplate(
			Predicate<TNode> predicate
			)
		{
			if (predicate == null) throw new ArgumentNullException("predicate");
			this.Predicate = predicate;
		}

		public override bool Inspect(object value)
		{
			if (!(value is TNode))return false;
			TNode obj = (TNode)value;

			bool matches = this.Predicate(obj);
			if (matches)
			{
				this.CapturedValue = obj;
			}

			return matches;
		}
	}
}
